package com.forezp.thinking.chapter14.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by forezp on 2017/12/4.
 */
public class DynamicProxyHandler implements InvocationHandler {

    private Object target;

    public DynamicProxyHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {


        System.out.println("DynamicProxyHandler:" + proxy.getClass() + "method:" +
                method + "args" + args);

        if (method.getName().equals("doSomethingElse")) {
            System.out.println("proxy detect doSomethingElse");
        }
        return method.invoke(target, args);
    }
}
